/**
 * @Description: 模型运行相关
 * @Date: 2020-04-22 09:06:54
 */
 $(function() {
    if (!window.layer) {
        layer = top.layer;
    }
    if (!window.layui) {
        layui = top.layui;
    }
    var $fmap;
    if ($('#fmap').length) {
        $fmap = $('#fmap');
    } else {
        $fmap = parent.$('#fmap');
    }

    // // 加载js
    // function loadJs (url) {
    //     //创建script标签
    //     var fileref = document.createElement('script');
    //     fileref.setAttribute("type", "text/javascript");
    //     fileref.setAttribute("src", url);
    // }

    // // 加载css
    // function loadCss (url) {
    //     //创建link标签
    //     var fileref = document.createElement('link');
    //     fileref.setAttribute("rel", "stylesheet");
    //     fileref.setAttribute("type", "text/css");
    //     fileref.setAttribute("href", url);
    // }

    // loadCss('/css/BasePlatform/User/userManagement.css');
    // loadCss('/ThirdParty/layer/css/layui.css');

    // loadJs('/ThirdParty/layer/layer.js');
    // loadJs('/ThirdParty/layer/layui.js');    

    var modelOrigin = $('#modelOrigin').val();
    var configInfo = InitialParameter("/Config.json");
    var modelURL = configInfo["modelTree"].type + '://' + configInfo["modelTree"].value
    var fileUploadOrigin = $('#fileUploadOrigin').val();
    // var userno = GetUserNO() || 'userno'; 
    var userno = getCookie('portaluserno') || 'userno';

    var username = GetUserChinaName() || 'username';
    var layerIndex;
    var modelName;
    var resourceid;
    var analysisFactors = null,checkedFactors = null,factorTxt = '';
    var xzqName = '';

    String.prototype.endWith = function(endStr) {
        var d = this.length - endStr.length;
        return (d >= 0 && this.lastIndexOf(endStr) == d);
    };
    /* 模型监控点击内容 */
    window.showModelDriven = function(text, rid,meunNO) {
        // text = '耕地质量等别评价';
        // modelName = '耕地质量等别评价';
        factorTxt = text;
        resourceid = rid;
        analysisFactors = null
        //获取分析因子
        if(meunNO){
            $.ajax({
                type: "post",
                async: false,
                url: modelURL + "/sw/apply/getAnalysisFactor",
                data: //发送到服务器的参数
                {
                    menuNo:meunNO
                },
                datatype: "json",
                success: function(res) {
                    let results = JSON.parse(res)
                    if(results.code == 200){
                        analysisFactors = results.data;
                    }else{
                        layer.msg("分析因子获取失败！",{icon:5})
                    }
                },
                error: function(err) {
                    if (err.status == 405)
                        top.location.href = '/';
                }
            });
        }

        if ($('#analyseContent').width() != 0) {
            $('#analyseTab').click();
        }
        layer.close(layerIndex);

        modelName = text;
        var url = modelOrigin + '/sw/gpTask/jobParam?modelName=' + this.encodeURIComponent(modelName);

        // soe
        if (modelName.endWith('图制作')) {
            url = modelOrigin + '/sw/soeTask/jobParam?modelName=' + this.encodeURIComponent(modelName);
        }

        // var res = {
        //     "msg": "获取成功",
        //     "code": 200,
        //     "data": {
        //         "modelName": "符合土地利用总体规划分析",
        //         "data": [
        //             // {
        //             //     "required": "true",
        //             //     "processor": "1",
        //             //     "input": "true",
        //             //     "id": "3",
        //             //     "name": "用户自定义范围",
        //             //     "modelparamname": "jsonFeature/inputSde",
        //             //     "typeparamname": "IsJson",
        //             //     "customer": "true",
        //             //     "formtype": "JSON/FILE",
        //             //     "type": "string",
        //             //     "value": "",
        //             //     "comment": "用户指定的自定义范围",
        //             //     "isfilename": "false",
        //             //     "issdename": "false",
        //             //     "filetype": [
        //             //         { "type": "SHP" },
        //             //         { "type": "JSON" },
        //             //         { "type": "SDE" }
        //             //     ]
        //             // },
        //             {
        //                 "required": "true",
        //                 "processor": "1",
        //                 "input": "false",
        //                 "id": "4",
        //                 "name": "日期",
        //                 "modelparamname": "testToDBTemp",
        //                 "customer": "true",
        //                 "formtype": "date",
        //                 "type": "string",
        //                 "value": "",
        //                 "comment": "建设用地管制区合规性分析结果",
        //                 "isfilename": "false",
        //                 "issdename": "true",
        //                 "isjsonname": "false"
        //             },
        //             {
        //                 "required": "true",
        //                 "processor": "1",
        //                 "input": "false",
        //                 "id": "5",
        //                 "name": "分析结果（保存文件名称）",
        //                 "modelparamname": "outName",
        //                 "customer": "true",
        //                 "formtype": "input",
        //                 "type": "string",
        //                 "value": "",
        //                 "comment": "建设用地管制区合规性分析结果",
        //                 "isfilename": "true",
        //                 "issdename": "false",
        //                 "isjsonname": "false"
        //             },
        //             { "required": "true", "processor": "1", "input": "false", "id": "6", "name": "分析结果（保存json数据名称）", "modelparamname": "outJsonName", "customer": "true", "formtype": "input", "type": "string", "value": "", "comment": "建设用地管制区合规性分析结果", "isfilename": "false", "issdename": "false", "isjsonname": "true" }
        //         ]
        //     }
        // }

        // var res = { "msg": "获取成功", "code": 200, "data": { "modelName": "土地利用现状专题图制作", "data": [{ "processor": "1", "input": "true", "id": "1", "name": "制图范围", "modelparamname": "Dm/Dm", "typeparamname": "Type", "customer": "true", "formtype": "JSON/SDE/FILE/XZQ/TFH", "type": "string", "value": "", "comment": "制图范围", "isfilename": "false", "issdename": "false", "isjsonname": "false", "filetype": [{ "type": "SHP" }, { "type": "SDE" }], "treelist": [{ "ID": "130000", "NAME": "河北省" }, { "PID": "130000", "ID": "130100", "NAME": "石家庄市" }, { "PID": "130100", "ID": "130102", "NAME": "长安区" }, { "PID": "130100", "ID": "130104", "NAME": "桥西区" }, { "PID": "130100", "ID": "130105", "NAME": "新华区" }, { "PID": "130100", "ID": "130107", "NAME": "井陉矿区" }, { "PID": "130100", "ID": "130108", "NAME": "裕华区" }, { "PID": "130100", "ID": "130121", "NAME": "井陉县" }, { "PID": "130100", "ID": "130123", "NAME": "正定县" }, { "PID": "130100", "ID": "130124", "NAME": "栾城县" }, { "PID": "130100", "ID": "130125", "NAME": "行唐县" }, { "PID": "130100", "ID": "130126", "NAME": "灵寿县" }, { "PID": "130100", "ID": "130127", "NAME": "高邑县" }, { "PID": "130100", "ID": "130128", "NAME": "深泽县" }, { "PID": "130100", "ID": "130129", "NAME": "赞皇县" }, { "PID": "130100", "ID": "130130", "NAME": "无极县" }, { "PID": "130100", "ID": "130131", "NAME": "平山县" }, { "PID": "130100", "ID": "130132", "NAME": "元氏县" }, { "PID": "130100", "ID": "130133", "NAME": "赵县" }, { "PID": "130100", "ID": "130181", "NAME": "辛集市" }, { "PID": "130100", "ID": "130182", "NAME": "藁城市" }, { "PID": "130100", "ID": "130183", "NAME": "晋州市" }, { "PID": "130100", "ID": "130184", "NAME": "新乐市" }, { "PID": "130100", "ID": "130185", "NAME": "鹿泉市" }, { "PID": "130000", "ID": "130200", "NAME": "唐山市" }, { "PID": "130200", "ID": "130202", "NAME": "路南区" }, { "PID": "130200", "ID": "130203", "NAME": "路北区" }, { "PID": "130200", "ID": "130204", "NAME": "古冶区" }, { "PID": "130200", "ID": "130205", "NAME": "开平区" }, { "PID": "130200", "ID": "130207", "NAME": "丰南区" }, { "PID": "130200", "ID": "130208", "NAME": "丰润区" }, { "PID": "130200", "ID": "130223", "NAME": "滦县" }, { "PID": "130200", "ID": "130224", "NAME": "滦南县" }, { "PID": "130200", "ID": "130225", "NAME": "乐亭县" }, { "PID": "130200", "ID": "130227", "NAME": "迁西县" }, { "PID": "130200", "ID": "130229", "NAME": "玉田县" }, { "PID": "130200", "ID": "130230", "NAME": "唐海县" }, { "PID": "130200", "ID": "130232", "NAME": "汉沽管理区" }, { "PID": "130200", "ID": "130233", "NAME": "南堡开发区" }, { "PID": "130200", "ID": "130281", "NAME": "遵化市" }, { "PID": "130200", "ID": "130283", "NAME": "迁安市" }, { "PID": "130000", "ID": "130300", "NAME": "秦皇岛市" }, { "PID": "130300", "ID": "130302", "NAME": "海港区" }, { "PID": "130300", "ID": "130303", "NAME": "山海关区" }, { "PID": "130300", "ID": "130304", "NAME": "北戴河区" }, { "PID": "130300", "ID": "130321", "NAME": "青龙满族自治县" }, { "PID": "130300", "ID": "130322", "NAME": "昌黎县" }, { "PID": "130300", "ID": "130323", "NAME": "抚宁县" }, { "PID": "130300", "ID": "130324", "NAME": "卢龙县" }, { "PID": "130000", "ID": "130400", "NAME": "邯郸市" }, { "PID": "130400", "ID": "130402", "NAME": "邯山区" }, { "PID": "130400", "ID": "130403", "NAME": "丛台区" }, { "PID": "130400", "ID": "130404", "NAME": "复兴区" }, { "PID": "130400", "ID": "130406", "NAME": "峰峰矿区" }, { "PID": "130400", "ID": "130421", "NAME": "邯郸县" }, { "PID": "130400", "ID": "130423", "NAME": "临漳县" }, { "PID": "130400", "ID": "130424", "NAME": "成安县" }, { "PID": "130400", "ID": "130425", "NAME": "大名县" }, { "PID": "130400", "ID": "130426", "NAME": "涉县" }, { "PID": "130400", "ID": "130427", "NAME": "磁县" }, { "PID": "130400", "ID": "130428", "NAME": "肥乡县" }, { "PID": "130400", "ID": "130429", "NAME": "永年县" }, { "PID": "130400", "ID": "130430", "NAME": "邱县" }, { "PID": "130400", "ID": "130431", "NAME": "鸡泽县" }, { "PID": "130400", "ID": "130432", "NAME": "广平县" }, { "PID": "130400", "ID": "130433", "NAME": "馆陶县" }, { "PID": "130400", "ID": "130434", "NAME": "魏县" }, { "PID": "130400", "ID": "130435", "NAME": "曲周县" }, { "PID": "130400", "ID": "130481", "NAME": "武安市" }, { "PID": "130000", "ID": "130500", "NAME": "邢台市" }, { "PID": "130500", "ID": "130502", "NAME": "桥东区" }, { "PID": "130500", "ID": "130503", "NAME": "桥西区" }, { "PID": "130500", "ID": "130521", "NAME": "邢台县" }, { "PID": "130500", "ID": "130522", "NAME": "临城县" }, { "PID": "130500", "ID": "130523", "NAME": "内丘县" }, { "PID": "130500", "ID": "130524", "NAME": "柏乡县" }, { "PID": "130500", "ID": "130525", "NAME": "隆尧县" }, { "PID": "130500", "ID": "130526", "NAME": "任县" }, { "PID": "130500", "ID": "130527", "NAME": "南和县" }, { "PID": "130500", "ID": "130528", "NAME": "宁晋县" }, { "PID": "130500", "ID": "130529", "NAME": "巨鹿县" }, { "PID": "130500", "ID": "130530", "NAME": "新河县" }, { "PID": "130500", "ID": "130531", "NAME": "广宗县" }, { "PID": "130500", "ID": "130532", "NAME": "平乡县" }, { "PID": "130500", "ID": "130533", "NAME": "威县" }, { "PID": "130500", "ID": "130534", "NAME": "清河县" }, { "PID": "130500", "ID": "130535", "NAME": "临西县" }, { "PID": "130500", "ID": "130581", "NAME": "南宫市" }, { "PID": "130500", "ID": "130582", "NAME": "沙河市" }, { "PID": "130000", "ID": "130600", "NAME": "保定市" }, { "PID": "130600", "ID": "130602", "NAME": "竞秀区" }, { "PID": "130600", "ID": "130606", "NAME": "莲池区" }, { "PID": "130600", "ID": "130607", "NAME": "满城区" }, { "PID": "130600", "ID": "130608", "NAME": "清苑区" }, { "PID": "130600", "ID": "130609", "NAME": "徐水区" }, { "PID": "130600", "ID": "130623", "NAME": "涞水县" }, { "PID": "130600", "ID": "130624", "NAME": "阜平县" }, { "PID": "130600", "ID": "130626", "NAME": "定兴县" }, { "PID": "130600", "ID": "130627", "NAME": "唐县" }, { "PID": "130600", "ID": "130628", "NAME": "高阳县" }, { "PID": "130600", "ID": "130629", "NAME": "容城县" }, { "PID": "130600", "ID": "130630", "NAME": "涞源县" }, { "PID": "130600", "ID": "130631", "NAME": "望都县" }, { "PID": "130600", "ID": "130632", "NAME": "安新县" }, { "PID": "130600", "ID": "130633", "NAME": "易县" }, { "PID": "130600", "ID": "130634", "NAME": "曲阳县" }, { "PID": "130600", "ID": "130635", "NAME": "蠡县" }, { "PID": "130600", "ID": "130636", "NAME": "顺平县" }, { "PID": "130600", "ID": "130637", "NAME": "博野县" }, { "PID": "130600", "ID": "130638", "NAME": "雄县" }, { "PID": "130600", "ID": "130681", "NAME": "涿州市" }, { "PID": "130600", "ID": "130682", "NAME": "定州市" }, { "PID": "130600", "ID": "130683", "NAME": "安国市" }, { "PID": "130600", "ID": "130684", "NAME": "高碑店市" }, { "PID": "130000", "ID": "130700", "NAME": "张家口市" }, { "PID": "130700", "ID": "130702", "NAME": "桥东区" }, { "PID": "130700", "ID": "130703", "NAME": "桥西区" }, { "PID": "130700", "ID": "130705", "NAME": "宣化区" }, { "PID": "130700", "ID": "130706", "NAME": "下花园区" }, { "PID": "130700", "ID": "130721", "NAME": "宣化县" }, { "PID": "130700", "ID": "130722", "NAME": "张北县" }, { "PID": "130700", "ID": "130723", "NAME": "康保县" }, { "PID": "130700", "ID": "130724", "NAME": "沽源县" }, { "PID": "130700", "ID": "130725", "NAME": "尚义县" }, { "PID": "130700", "ID": "130726", "NAME": "蔚县" }, { "PID": "130700", "ID": "130727", "NAME": "阳原县" }, { "PID": "130700", "ID": "130728", "NAME": "怀安县" }, { "PID": "130700", "ID": "130729", "NAME": "万全县" }, { "PID": "130700", "ID": "130730", "NAME": "怀来县" }, { "PID": "130700", "ID": "130731", "NAME": "涿鹿县" }, { "PID": "130700", "ID": "130732", "NAME": "赤城县" }, { "PID": "130700", "ID": "130733", "NAME": "崇礼县" }, { "PID": "130000", "ID": "130800", "NAME": "承德市" }, { "PID": "130800", "ID": "130802", "NAME": "双桥区" }, { "PID": "130800", "ID": "130803", "NAME": "双滦区" }, { "PID": "130800", "ID": "130804", "NAME": "鹰手营子矿区" }, { "PID": "130800", "ID": "130821", "NAME": "承德县" }, { "PID": "130800", "ID": "130822", "NAME": "兴隆县" }, { "PID": "130800", "ID": "130823", "NAME": "平泉县" }, { "PID": "130800", "ID": "130824", "NAME": "滦平县" }, { "PID": "130800", "ID": "130825", "NAME": "隆化县" }, { "PID": "130800", "ID": "130826", "NAME": "丰宁满族自治县" }, { "PID": "130800", "ID": "130827", "NAME": "宽城满族自治县" }, { "PID": "130800", "ID": "130828", "NAME": "围场满族蒙古族自治县" }, { "PID": "130000", "ID": "130900", "NAME": "沧州市" }, { "PID": "130900", "ID": "130902", "NAME": "新华区" }, { "PID": "130900", "ID": "130903", "NAME": "运河区" }, { "PID": "130900", "ID": "130921", "NAME": "沧县" }, { "PID": "130900", "ID": "130922", "NAME": "青县" }, { "PID": "130900", "ID": "130923", "NAME": "东光县" }, { "PID": "130900", "ID": "130924", "NAME": "海兴县" }, { "PID": "130900", "ID": "130925", "NAME": "盐山县" }, { "PID": "130900", "ID": "130926", "NAME": "肃宁县" }, { "PID": "130900", "ID": "130927", "NAME": "南皮县" }, { "PID": "130900", "ID": "130928", "NAME": "吴桥县" }, { "PID": "130900", "ID": "130929", "NAME": "献县" }, { "PID": "130900", "ID": "130930", "NAME": "孟村回族自治县" }, { "PID": "130900", "ID": "130981", "NAME": "泊头市" }, { "PID": "130900", "ID": "130982", "NAME": "任丘市" }, { "PID": "130900", "ID": "130983", "NAME": "黄骅市" }, { "PID": "130900", "ID": "130984", "NAME": "河间市" }, { "PID": "130000", "ID": "131000", "NAME": "廊坊市" }, { "PID": "131000", "ID": "131002", "NAME": "安次区" }, { "PID": "131000", "ID": "131003", "NAME": "广阳区" }, { "PID": "131000", "ID": "131022", "NAME": "固安县" }, { "PID": "131000", "ID": "131023", "NAME": "永清县" }, { "PID": "131000", "ID": "131024", "NAME": "香河县" }, { "PID": "131000", "ID": "131025", "NAME": "大城县" }, { "PID": "131000", "ID": "131026", "NAME": "文安县" }, { "PID": "131000", "ID": "131028", "NAME": "大厂回族自治县" }, { "PID": "131000", "ID": "131081", "NAME": "霸州市" }, { "PID": "131000", "ID": "131082", "NAME": "三河市" }, { "PID": "130000", "ID": "131100", "NAME": "衡水市" }, { "PID": "131100", "ID": "131102", "NAME": "桃城区" }, { "PID": "131100", "ID": "131121", "NAME": "枣强县" }, { "PID": "131100", "ID": "131122", "NAME": "武邑县" }, { "PID": "131100", "ID": "131123", "NAME": "武强县" }, { "PID": "131100", "ID": "131124", "NAME": "饶阳县" }, { "PID": "131100", "ID": "131125", "NAME": "安平县" }, { "PID": "131100", "ID": "131126", "NAME": "故城县" }, { "PID": "131100", "ID": "131127", "NAME": "景县" }, { "PID": "131100", "ID": "131128", "NAME": "阜城县" }, { "PID": "131100", "ID": "131181", "NAME": "冀州市" }, { "PID": "131100", "ID": "131182", "NAME": "深州市" }] }, { "processor": "1", "input": "false", "id": "2", "name": "输出成果名称", "modelparamname": "Name", "customer": "true", "formtype": "input", "type": "string", "value": "", "comment": "土地利用现状专题图制作结果", "isfilename": "false", "issdename": "true", "isjsonname": "false" }, { "processor": "1", "input": "false", "id": "3", "name": "文件类型", "modelparamname": "ExportFormat", "customer": "true", "formtype": "option", "type": "string", "value": "", "comment": "文件类型", "isfilename": "true", "issdename": "false", "isjsonname": "false", "option": [{ "id": "PNG", "name": "PNG" }, { "id": "JPG", "name": "JPG" }, { "id": "PDF", "name": "PDF" }] }] } }

        // showModelInput(res);


        // return

        // 获取模型需要的参数
        $.ajax({
            type: 'get',
            async: true,
            url: url,
            success: function(res) {
                if (typeof(res) == 'string') {
                    res = JSON.parse(res);
                }
                window.res = res;
                if (res.code == '200') {
                    showModelInput(res);
                } else {
                    layui.layer.msg(res.msg, {
                        shade: 0.3,
                        time: 1000 // 1秒关闭
                    });
                }
                layer.closeAll('loading');
            },
            error: function(err) {
                console.log(err);
            }
        });
    };

    /* 展示模型输入框 */
    //  width: calc(100% - 220px);
function showModelInput(res, factors) {
        var html = `
            <div style="width: 100%; height: 100%;overflow: hidden;padding:10px;">
                <div class="container_Div_main" style=" width: 100%;height: 100%;">
                    <div class="content" style="width:100%;height: 100%;display: inline-block; border-radius: 2px; overflow-y: auto;">
                        <div style="height:30px;">
                            <div style="display: flex;width: 100%;height:30px;">
                                <div class="content_head_span"></div>
                                <div style="margin-left: 5px;color:#00000094;">分析名称</div>
                            </div>
                        </div> 
                        <div style="height:50px;">
                            <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="text" name="title" value="${res.data.modelName}" autocomplete="off" class="layui-input" id="fxName">
                            </div>
                            </div>
                        </div>
                        <div modelName="` + res.data.modelName + `" id="modelForm"  class="layui-form">
                            <div style="display: flex;width: 100%;height:30px;">
                                <div class="content_head_span"></div>
                                <div style="margin-left: 5px;color:#00000094;">分析范围</div>
                            </div>
                        `;
        // res.data.modelName
        // <form modelName="` + res.data.modelName + `" id="modelForm" class="layui-form" action="" >
    
        res.data.data.map(function(item, index) {
            html += `
                <div class="layui-form-item" itemRequired="` + item.required + `" formtype="` + item.formtype + `" typeparamname="` + item.typeparamname + `" modelparamname="` + item.modelparamname + `" id="` + item.id + `" name="` + item.name + `" comment="` + item.comment + `" style="margin-bottom: 20px !important;">
    
                    <label class="layui-form-label" style="display:none;">` + item.name + `</label>
                        <div class="layui-input-block">`
    
            // html += `<div id="` + item.id + `" class="formItem" comment="` + item.comment + `">
            // <label class="formLabel">` + item.name + `</label>`;
            switch (item.formtype) {
                case 'date':
                    html += `<input type="text" class="dateInput layui-input layui-inputNew" id="date-` + item.id + `" defaultValue="` + item.value + `">`
                    break
                    // 输入框
                case "input":
                    html += `
                <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入` + item.name + `" class="layui-input layui-inputNew" value="` + item.value + `">`
                    break;
                    // 下拉框
                case "option":
                    html += `<select name="` + item.name + `" lay-filter="value">`;
                    // html += `<option value = "">请选择` + item.name + `</option>`;
                    item.option.map(function(ite) {
                        html += `<option value="` + ite.id + `">` + ite.name + `</option>`
                    });
                    html += `</select>`;
                    break;
                    // 单选
                case "radio":
                    item.option.map(function(ite) {
                        html += `<input lay-filter="value" type="radio" name="` + item.id + `" value="` + ite.id + `" title="` + ite.name + `">`;
                    });
                    break;
                    // 多选
                case "check":
                    item.option.map(function(ite) {
                        html += `<input lay-filter="value" lay-skin="primary" type="checkbox" name="` + item.id + `" value="` + ite.id + `" title="` + ite.name + `" name="like1[read]">`;
                    });
                    break;
                    // 树
                case "treelist":
                    html += `
    <input type="text" name="title" readonly lay-verify="title" autocomplete="off" placeholder="请选择` + item.name + `" class="layui-input layui-inputNew" value="` + item.value + `">`
                    html += `<div style="display:block; width:100%; position:initial">
            <ul id="menu_tree_left" class="ztree"></ul>
        </div>`;
    
                    var settingLeft = {
                        view: {
                            dblClickExpand: false, //双击节点时，是否自动展开父节点的标识
                            showLine: false, //是否显示节点之间的连线
                            showIcon: true,
                            fontCss: {
                                'color': 'white',
                                'font-weight': 'normal'
                            }, //字体样式函数
                            selectedMulti: false //设置是否允许同时选中多个节点
                        },
                        check: {
                            //chkboxType: { "Y": "ps", "N": "ps" },
                            chkStyle: "checkbox", //复选框类型
                            enable: false //每个节点上是否显示 CheckBox
                        },
                        data: {
                            simpleData: { //简单数据模式
                                enable: true,
                                idKey: "id",
                                pIdKey: "pid",
                                rootPId: "150000"
                            }
                        },
                        callback: {
                            onClick: function(event, treeId, treeNode) {
                                zTree = $.fn.zTree.getZTreeObj("menu_tree_left");
                                if ($(event.target).hasClass('ico_close') || $(event.target).hasClass('ico_open')) {
                                    zTree.expandNode(treeNode); //如果是父节点，则展开该节点
                                }
                                var text = $(event.target).text();
                                // console.log(treeNode);
                                if (text) {
                                    $('#orgInput').attr('checkId', treeNode.id);
                                    $('#orgInput').val(text);
                                    $('#ztreeDiv').hide();
                                }
                            },
                        }
                    };
                    var zNodes = item.treelist.map(function(item, index) {
                        var node = {
                            id: item.ID,
                            pid: item.PID,
                            name: item.NAME
                        };
    
                        if (item.PID == '') {
                            node.open = true;
                        }
                        return node;
                    });
    
                    setTimeout(function() {
                        $.fn.zTree.init($("#menu_tree_left"), settingLeft, zNodes);
                    }, 200);
    
                    item.treelist.map(function(ite) {
                        // html += `<input lay-filter="value" lay-skin="primary" type="checkbox" name="` + item.ID + `" value="` + ite + `" title="` + ite + `" name="like1[read]">`;                        
                        //初始化菜单树
                    });
                    break;
    
                case "variableArray":
                    var paramHtml = '';
                    paramHtml += `<div class="" style="position: relative; margin-bottom: 10px;" onmouseover="if($(this).next().length) {
    $(this).find('.delateIcon').show();
    }"
    onmouseout="$(this).find('.delateIcon').hide();">`;
    
                    item.PARAM.map(function(ite) {
                        paramHtml += `<div modelparamname="` + ite.modelparamname + `" class="layui-input-inline" style="width: calc(((100% - 10px) / 3) - 10px);height: 32px;float: none;">`;
                        switch (ite.formtype) {
                            // 输入框
                            case "input":
                                paramHtml += `
                <input oninput="inputChange(this)" type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入` + ite.name + `" class="layui-input layui-inputNew" value="">`;
                                break;
                                // 下拉框
                            case "option":
                                paramHtml += `<select name="` + ite.name + `" lay-filter="value2">`;
                                paramHtml += `<option value="">请选择` + ite.name + `</option>`;
                                ite.option.map(function(ite) {
                                    paramHtml += `<option nextunable="` + ite.nextunable + `" value="` + ite.id + `">` + ite.name + `</option>`
                                });
                                paramHtml += `</select>`;
                                break;
                            default:
                        }
                        paramHtml += `</div>`;
                    });
                    paramHtml += `<i class="delateIcon" onclick="$(this).parent().remove();"></i>` + `</div>`
    
                    html += paramHtml;
                    break;
    
                default:
                    var html2 = '';
                    html += `<div class="layui-input-inline" style="width:100%; display:flex;justify-content: center;">`;
                    var arr = item.formtype.split('/');
                    // arr = ['XZQ','FILE','JSON']
                    // 按预定顺序
                    if (arr.indexOf('XZQ') >= 0) {
                        html += `<i class="model_icon XZQ" value="XZQ" title="选择行政区划"></i>`;
                        html2 += `<div class="XZQSelect layui-input-inline" style="width:100%; height:32px; display:none;z-index: 9;margin-top: 20px;">`;
    
                        html2 += `<input type="text" name="title" readonly lay-verify="title" autocomplete="off" placeholder="请选择行政区划" class="layui-input layui-inputNew XZQinput" value="" onclick={$(this).next().show()}>`;
                        html2 += `<div class="ztreeDiv" style="display:none; width:100%; position:initial" tabindex="0" contenteditable="true">
            <ul id="` + item.name + `XZQ" class="ztree"></ul>
        </div>`;
                        html2 += '</div>';
    
                        var settingLeft = {
                            view: {
                                dblClickExpand: false, //双击节点时，是否自动展开父节点的标识
                                showLine: false, //是否显示节点之间的连线
                                showIcon: true,
                                fontCss: {
                                    'color': 'white',
                                    'font-weight': 'normal'
                                }, //字体样式函数
                                selectedMulti: false //设置是否允许同时选中多个节点
                            },
                            check: {
                                //chkboxType: { "Y": "ps", "N": "ps" },
                                chkStyle: "checkbox", //复选框类型
                                enable: false //每个节点上是否显示 CheckBox
                            },
                            data: {
                                simpleData: { //简单数据模式
                                    enable: true,
                                    idKey: "id",
                                    pIdKey: "pid",
                                    rootPId: ""
                                }
                            },
                            callback: {
                                onClick: function(event, treeId, treeNode) {
                                    var zTree = $.fn.zTree.getZTreeObj(treeId);
                                    if ($(event.target).hasClass('ico_close') || $(event.target).hasClass('ico_open')) {
                                        zTree.expandNode(treeNode); //如果是父节点，则展开该节点
                                    }
    
                                    var text = $(event.target).text();
                                    // console.log(treeNode);
                                    if (text) {
                                        $('#' + treeId).parent().hide();
                                        $('#' + treeId).parent().prev().val(text);
                                        $('#' + treeId).parent().prev().attr('nodeId', treeNode.id);
                                        $fmap[0].contentWindow.RemoveAllLayers();
                                        var result = $fmap[0].contentWindow.globleGetXZQFeature(treeNode.id)
                                        result = $fmap[0].contentWindow.handle2Geojson(result, "arcgis");
                                        $fmap[0].contentWindow.addXZQFeatures(result.features);
                                    }
                                },
                            }
                        };
    
                        var zNodes = item.treelist.map(function(item, index) {
                            var node = {
                                id: item.ID,
                                pid: item.PID,
                                name: item.NAME
                            };
    
                            if (!item.PID) {
                                node.open = true;
                            }
                            return node;
    
                        });
    
                        setTimeout(function() {
                            $.fn.zTree.init($("#" + item.name + 'XZQ'), settingLeft, zNodes);
                            $('.ztreeDiv').blur(function() {
                                $('.ztreeDiv').hide();
                            });
                        }, 200);
                    }
                    if (arr.indexOf('TFH') >= 0) {
                        html += `<i class="model_icon TFH" value="TFH" title="输入图符号"></i>`;
                        html2 += `<div class="TFHSelect layui-input-inline" style="width:100%; height:32px; display:none">`;
                        html2 += `<input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入图符号" class="layui-input layui-inputNew TFHinput" value="">`;
                        html2 += `</div>`
                    }
                    if (arr.indexOf('SDE') >= 0) {
                        // html += `<option value="SDE">选择已有资源</option>`;
                        html += `<i class="model_icon SDE" value="SDE" title="选择已有资源" style="display:none;"></i>`;
                        // 选库
                        html2 += `<div class="databaseSelect layui-input-inline SDE-div" style="width:calc(50% - 15px);float:left; height:32px; display:none;margin-top: 25px;">
                    <select name="" lay-filter="database">`;
                        html2 += `<option value = "">请选择数据库</option>`;
                        if (item.SDE) {
                            item.SDE.map(function(ite) {
                                html2 += `<option value="` + ite.id + `/` + ite.sdeName + `">` + ite.name + `</option>`;
                            });
                        } else {
                            // 区分GA\ GP： GA的模型后面有“(大数据)”
                            // （2为GP、 5为GA）
                            var type;
                            if (modelName.indexOf('(大数据)') > -1) {
                                // GA
                                type = '5';
                            } else {
                                // GP
                                type = '2';
                            }
                            // 获取全部可用sde库，不需要参数
                            $.ajax({
                                type: 'get',
                                async: false,
                                url: modelOrigin + '/sw/sde/dbMessage',
                                datatype: 'json',
                                data: {
                                    type: type //（2为GP、 5为GA）
                                },
                                success: function(res) {
                                    if (typeof res == 'string') {
                                        res = JSON.parse(res);
                                    }
                                    if (res.code == 200) {
                                        res.data.map(function(ite) {
                                            html2 += `<option value="` + ite.id + `/` + ite.sdeName + `">` + ite.name + `</option>`;
                                        });
                                    } else {
                                        alert(res.msg);
                                    }
                                    console.log(res);
                                },
                                error: function(err) {
                                    console.log(err);
                                    alert('获取可用sde库失败');
                                }
                            });
                        }
                        html2 += `</select></div>`;
    
                        // 选表
                        html2 += `<div class="databaseSelect layui-input-inline SDE-div" style="width:calc(50% - 15px);float:right; height:32px;  display:none;margin-top: 25px;">
                    <select class="tableSelect" name="" lay-filter="table">`;
                        html2 += `<option value = "">请选择数据库表</option>`
                        html2 += `</select>
                    </div>`;
    
                        // json
                        // 选择图层
                        // html2 += `<div class="jsonInput layui-input-inline JSON-div jsonInput-layer" style="width:calc((100% - 10px) / 3 - 10px); height:32px;  display:none"><select id="layerSelect" name="" lay-filter="layer">`;
                        // html2 += `<option value = "">请选择图层</option>`
                        // html2 += `</select>
                        // </div>`;
    
                        html2 += `<div class="jsonInput layui-input-inline JSON-div" style="width:calc((100% - 10px) / 3 - 10px); height:32px;  display:none">`;
                        html2 += `<a class="drawBtn layui-layer-btn0" style="
        display: inline-block;
        background-color: #1E9FFF;
        color: #fff;
        line-height: 28px;
        margin: 2px 10px;
        padding: 0 15px;
        border-radius: 2px;
        cursor:pointer">粘贴</a></div>`;
                        html2 += ` <textarea placeholder="选择或绘制结果" class="jsonInput layui-textarea JSON-div json-textarea" style="top:10px;  display:none"></textarea>`;
    
                        // 上传文件
                        // html2 += `<div class="filesInput layui-input-inline JSON-div" style="width:calc((100% - 10px) / 3 - 10px); height:32px; display:none"><select id="fileType" name="" lay-filter="fileType">`;
                        // html2 += `<option value = "">请选择文件类型</option>`
                        // item.filetype.map(function (ite) {
                        //     html2 += `<option value = "` + ite.type + `">` + ite.type + `</option>`
                        // })
                        // html2 += `</select>
                        // </div>`;
    
                        html2 += `<div class="filesInput layui-input-inline JSON-div" style="display:none;margin-top: 25px;width: 100%;">`;
                        html2 += `<a class="layui-layer-btn0 uploadBtn" style="
        width:calc(50% - 10px);
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #1E9FFF;
        color: #fff;
        margin: 2px 0px;
        border-radius: 2px;
        cursor: pointer;">选择文件(.zip/.rar)</a>` +
                            `<a class="layui-layer-btn0" style="
        width:calc(50% - 10px);
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #1E9FFF;
        color: #fff;
        margin: 2px 10px;
        border-radius: 2px;
        cursor: pointer;" onclick="$(this).parent().next('.uploaded').html(''); $(this).parent().siblings('input').val(''); $(this).parents('.layui-form-item')[0].formData = null;$(this).parents('.layui-form-item').attr('fileName','')">清空</a>` +
                            `</div><div style="float: left;margin-top:8px" class="filesInput  uploaded"></div>` +
                            // `<span>未选择任何文件</span>`+
                            `<input class="uploadFile" type="file" style="display:none">
            `;
                    }
                    if (arr.indexOf('FILE') >= 0) {
                        // html += `<option value="FILE">上传图形文件</option>`;
                        html += `<i class="model_icon FILE" value="FILE" title="上传图形文件"></i>`;
                    }
                    if (arr.indexOf('JSON') >= 0) {
                        // html += `<option value="JSON1">地图上选择要素</option>`;
                        // html += `<option value="JSON2">绘制</option>`;
                        html += `<i class="model_icon JSON1" value="JSON1" title="地图上选择要素" style="display:none;"></i>`;
                        html += `<i class="model_icon JSON2" value="JSON2" title="绘制"></i>`;
                    }
                    //if (arr.indexOf('coordinate') >= 0) {
                    //    // if (1) {
                    //    html += `<i class="model_icon coordinate" value="coordinate" title="输入坐标串"></i>`;
                    //    var result = $fmap[0].contentWindow.other_getProjectionsInfo();
                    //    html2 += `<div class="coordinateInput layui-input-inline" style="display:none; width: 100%;">`;
    
                    //    html2 += `<select class="coordinateSelect" name="" lay-filter="coordinate">`;
                    //    html2 += `<option value = "">请选择坐标系</option>`;
                    //    result.map(function(item, index) {
                    //        html2 += `<option class="hehe" title="` + item.title + `" value = "` + item.value + `">` + item.text + `</option>`
                    //    })
    
                    //    html2 += `</select>`
                    //    html2 += `<textarea placeholder="请输入坐标串" class="layui-textarea coordinateTextarea" style="top:10px;"></textarea>`
                    //    html2 += `</div>`
                    //}
                    html += `</div>`;
                    html += html2;
                    break;
            }
    
            html += `</div></div>
                    </div>  
                    <div style="height:30px;">
                        <div style="display: flex;width: 100%;height:30px;">
                            <div class="content_head_span"></div>
                            <div style="margin-left: 5px;color:#00000094;">分析因子</div>
                        </div>
                    </div> 
                    <div>
                    <form class="layui-form" id="checkFactorsForm" lay-filter="checkFactorsForm" action="" >
                        <div class="layui-form-item" pane="">
                        <div class="layui-input-block">`
        if(analysisFactors != null){
            for(var i = 0;i<analysisFactors.length;i++){
                var oneFactor = analysisFactors[i];
                if(factorTxt == "建设用地预审"||factorTxt == "建设用地审批"){
                    html += `<div>
                                <input type="checkbox" checked name=`+ oneFactor.name +` value = `+ oneFactor.name +` lay-skin="primary" title=`+ oneFactor.name +` lay-filter="checkFactors">
                            </div>`
                }else{
                    if(i == 0){
                        html += `<div>
                                <input type="checkbox" checked name=`+ oneFactor.name +` value = `+ oneFactor.name +` lay-skin="primary" title=`+ oneFactor.name +` lay-filter="checkFactors">
                            </div>`
                    }else{
                        html += `<div>
                                <input type="checkbox" name=`+ oneFactor.name +` value = `+ oneFactor.name +` lay-skin="primary" title=`+ oneFactor.name +` lay-filter="checkFactors">
                            </div>`
                    }
                }
            }
        }
        html += `</div></div></form></div></div></div></div>`
        layui.form.render();
        });
    
        // html += `</form></div><div id="commentNew" class="" style="float: left; width: 210px; height: 100%;display: inline-block;border:2px solid #63a0c4; border-radius: 2px; padding: 20px; color: silver;"></div></div></div>`
    
        var areaHeight = '350px';
        if (res.data.data.length > 1) {
            areaHeight = '600px';
        }
        layerIndex = layer.open({
            type: 1,
            title: modelName,
            content: html,
            offset: ['80px', '410px'],
            area: ['350px', areaHeight],
            closeBtn: 1,
            shadeClose: true,
            shade: 0,
            // shadeClose: true, //点击遮罩关闭
            // maxmin: true,
            resize: false,
            btn: ['运行'],
            cancel: function(index, layero) {
                layer.close(index);
                if ($fmap[0].contentWindow.RemoveAllLayers) {
                    $fmap[0].contentWindow.RemoveAllLayers();
                }
            },
            btn1: function(index, layero) {
                startModel();
                //layer.close(index);
            },
            btn2: function(index, layero) {
                layer.close(index);
                if ($fmap[0].contentWindow.RemoveAllLayers) {
                    $fmap[0].contentWindow.RemoveAllLayers();
                }
            },
        });
    
        // $('.layui-form-item').hover(function (e) {
        //     var comment = $(e.currentTarget).attr('comment');
        //     $('#commentNew').html(comment);
        // }, function () {
        //     $('#commentNew').html('');
        // });
    
        // 展示comment
        $('.layui-form-item').on('click', function(e) {
            var comment = $(e.currentTarget).attr('comment');
            $('#commentNew').html(comment);
        });
    
        layui.use('form', function() {
            var form = layui.form;
    
            // 选择范围(点击图标)
            $('.model_icon').on('click', function() {
                var $this = $(this);
                var value = $this.attr('value');
                $(this).parents('.layui-form-item').attr({
                    'formtype': value,
                    'formtypeNew': value,
                })
                $this.siblings().removeClass('active');
                $this.addClass('active');
                $this.parent().parent().find('.XZQSelect, .TFHSelect, .databaseSelect, .jsonInput, .filesInput, .coordinateInput').hide();
                $('.ztreeDiv').hide();
    
                if (value == '') {
                    // 恢复默认,啥也不干
                }
                if (value == 'XZQ') {
                    $this.parent().parent().find('.XZQSelect').show();
                }
                if (value == 'TFH') {
                    $this.parent().parent().find('.TFHSelect').show();
                }
                if (value == 'SDE') {
                    // 请求库, 表
                    $this.parent().parent().find('.databaseSelect').show();
                }
                if (value == 'FILE') {
                    // 上传图形文件
                    $this.parent().parent().find('.filesInput').show();
                }
                if (value == 'JSON1') {
                    // 地图上选择要素(要先选择图层)
                    $this.parent().parent().find('.drawBtn').addClass('unable');
                    $this.parent().parent().find('.drawBtn').css({
                        'cursor': 'not-allowed'
                    });
                    $this.parent().parent().find('textarea').val('');
    
                    //////// $this.parent().parent().find('.jsonInput').show();
                    //$this.parent().parent().find('.drawBtn').show();
                    //$this.parent().parent().find('.drawBtn').parent().show();
                    //$this.parent().parent().find('.drawBtn').css({
                    //    'cursor': 'pointer'
                    //});
                    //$this.parent().parent().find('.jsonInput-layer').hide();
                    $fmap[0].contentWindow.identifyQuery(2, true);
    
                    //var thisResult = $fmap[0].contentWindow.other_copyHeightLight();
                    //if (thisResult) {
                    //    $this.parent().parent().find('.drawBtn').removeClass('unable');
                    //}
    
    
                    // if (![0].contentWindow.other_getOpenLayers) {
                    //     alert('请等页面加载完后重试')
                    //     $this.removeClass('active');
                    //     return
                    // }
                    // var result = [0].contentWindow.other_getOpenLayers()
                    // if (result != null) {
                    //     var html = `<option value = "">请选择图层</option>`;
                    //     for (var key in result) {
                    //         html += `<option value = "` + key + `">` + result[key] + `</option>`
                    //     }
                    //     $('#layerSelect').html(html);
                    //     layui.use('form', function () {
                    //         var form = layui.form;
                    //         form.render("select");
                    //     })
                    //     $('.jsonInput').show();
                    // } else {
                    //     alert('请勾选图层后重试')
                    //     $this.removeClass('active');
                    //     return;
                    // }
                }
                if (value == 'JSON2') {
                    $('#mySource').click();
                    $('#header_tab2').click();
                    // 绘制
                    // $this.parent().parent().find('.drawBtn').removeClass('unable');
                    // $this.parent().parent().find('.drawBtn').css({
                    //     'cursor': 'pointer'
                    // });
                    //alert('请在地图上绘制要素');
    
                    $this.parent().parent().find('textarea').val('');
                    /////////// $this.parent().parent().find('.jsonInput').show();
                    $this.parent().parent().find('.drawBtn').hide();
                    $this.parent().parent().find('.jsonInput-layer').hide();
    
                    if (!$fmap[0].contentWindow.DrawFigure) {
                        alert('请等地图页面加载完后重试')
                        $this.removeClass('active');
                        return
                    }
    
                    // layer.min(layerIndex);
                    $fmap[0].contentWindow.DrawFigure(["point", "polyline", "polygon"], function(thisResult,xzq) {
                        // console.log(thisResult);
                        setTimeout(function() {
                            layer.restore(layerIndex)
                        }, 500);
                        // $this.parent().parent().find('.json-textarea').show();
                        $this.parent().parent().find('.json-textarea').val(JSON.stringify(thisResult));
                        xzqName = xzq;
                        autoStartModel()
                    });
                }
                if (value == 'coordinate') {
                    $('.coordinateInput').show();
                }
            });
    
            // 选择范围
            // form.on('select(customize)', function (data) {
            //     console.log(this)
            //     var value = data.value;
    
            //     // value = 'SDE';
            //     // value = 'FILE';
            //     // value = 'JSON1';
            //     //  value = 'JSON2';
    
            //     // alert(value); //复选框value值，也可以通过data.elem.value得到
            //     $('.databaseSelect,.jsonInput,.filesInput').hide();
            //     if (value == '') {
            //         // 恢复默认,啥也不干
            //     }
            //     if (value == 'SDE') {
            //         // 请求库, 表
            //         $('.databaseSelect').show();
            //     }
            //     if (value == 'FILE') {
            //         // 上传图形文件
            //         $('.filesInput').show();
            //     }
    
            //     if (value == 'JSON1') {
            //         // 地图上选择要素(要先选择图层)
            //         $('#drawBtn').html('选择');
            //         if (!$fmap[0].contentWindow.other_getOpenLayers) {
            //             alert('请等页面加载完后重试')
            //             return
            //         }
            //         var result = $fmap[0].contentWindow.other_getOpenLayers()
            //         if (result != null) {
            //             var html = `<option value = "">请选择图层</option>`;
            //             for (var key in result) {
            //                 html += `<option value = "` + key + `">` + result[key] + `</option>`
            //             }
            //             $('#layerSelect').html(html);
            //             layui.use('form', function () {
            //                 var form = layui.form;
            //                 // form.on('select(layer)', function (data) {
            //                 //     var value = data.value;
            //                 // });
            //                 form.render("select");
            //             })
            //             $('.jsonInput').show();
            //         } else {
            //             alert('请勾选图层后重试')
            //         }
            //     }
            //     if (value == 'JSON2') {
            //         // 绘制
            //         $('#drawBtn').html('绘制');
            //         if (!$fmap[0].contentWindow.other_getOpenLayers) {
            //             alert('请等页面加载完后重试')
            //             return
            //         }
            //         $('.jsonInput').show();
            //         $('.jsonInput-layer').hide();
            //     }
            //     $(this).parents('.layui-form-item').attr({
            //         'formtype': value,
            //     })
            // });
    
            // 选择库
            form.on('select(database)', function(data) {
                var $this = $(this);
                var database = data.value;
                $this.parents('.layui-form-item').attr('database', database);
                console.log(database);
                if (!database) {
                    return;
                }
                // 请求表数据
                $.ajax({
                    type: 'get',
                    async: true,
                    url: modelOrigin + '/sw/sde/tableMessage?id=' + database.split('/')[0],
                    datatype: 'json',
                    success: function(res) {
                        if (typeof res == 'string') {
                            res = JSON.parse(res);
                        }
                        console.log(res);
                        if (res.code == 200) {
                            res = res.data;
                            var html = `<div class="layui-input-inline" style="width:100%;"><select class="tableSelect" name="" lay-filter="table">`;
                            html += `<option value = "">请选择数据库表</option>`
    
                            if (res) {
                                res.map(function(item) {
                                    html += `<option value = "` + item.id + `">` + item.name + `</option>`
                                })
                            }
                            html += `</select>
                        </div>`;
                            $this.parents('.layui-form-item').find('.tableSelect').html(html);
                            layui.use('form', function() {
                                var form = layui.form;
                                form.render("select");
                            })
                        } else {
                            alert(res.msg)
                        }
                    },
                    error: function(err) {
                        console.log(err);
                        alert('获取sde库中的表失败')
                    }
                });
    
                //var res = `[{"name":"一次图层","id":"dltbONE"},{"name":"二次图层","id":"dltbTWO"},{"name":"一次叠加结果","id":"teaaxa"},{"name":"二次叠加结果","id":"teaaxaa"},{"name":"二次叠加结果1","id":"testss"},{"name":"二次叠加结果2","id":"testtoccc"}]`;
            })
    
            // 选择库表
            form.on('select(table)', function(data) {
                var table = data.value;
                $(this).parents('.layui-form-item').attr('table', table);
                // autoStartModel()
            })
    
            // // 选择文件类型
            // form.on('select(fileType)', function (data) {
            //     var fileType = data.value;
            //     $(this).parents('.layui-form-item').attr('fileType', fileType);
            // })
    
            // 监听下拉
            form.on('select(value)', function(data) {
                // console.log(data.elem); //得到radio原始DOM对象
                // console.log(data.value); //被点击的radio的value值
                $(this).parents('.layui-form-item').attr('value', data.value);
            });
    
            // 监听单选
            form.on('radio(value)', function(data) {
                // console.log(data.elem); //得到radio原始DOM对象
                // console.log(data.value); //被点击的radio的value值
                $(this).parents('.layui-form-item').attr('value', data.value);
            });
    
            // 监听复选
            form.on('checkbox(value)', function(data) {
                // console.log(data.elem); //得到checkbox原始DOM对象
                // console.log(data.elem.checked); //是否被选中，true或者false
                // console.log(data.value); //复选框value值，也可以通过data.elem.value得到
                // console.log(data.othis); //得到美化后的DOM对象
                var value = '';
                $(this).parent().find('input').each(function(index, item) {
                    if (item.checked) {
                        if (value != '') {
                            value += ','
                        }
                        value += item.value;
                    }
                })
                $(this).parents('.layui-form-item').attr('value', value);
            });

            //监听分析因子复选
            form.on('checkbox(checkFactors)',function(data){
                var datas = form.val('checkFactorsForm');
                var Length = 0;
                for (var item in datas) {
                    Length++;
                }
                if(Length < 1){
                    alert("至少选择一个分析因子！");
                    $(data.elem).prop("checked",true);
                    form.render();
                }
            });
            // 监听下拉2
            form.on('select(value2)', function(data) {
                var value = data.value;
                $(data.elem).parent().attr({
                    value: value
                })
                if (data.value) {
                    $(data.elem).parent().parent().addClass('paramItem');
                    inputChange(data.elem)
                }
                $(data.elem.options).each(function(index, item) {
                    var val = $(item).val();
                    if (value == val) {
                        if ($(item).attr('nextunable') == 'true') {
                            $(data.elem).parent().next().hide();
                        } else {
                            $(data.elem).parent().next().show();
                        }
                    }
                })
                console.log(data.elem); //得到radio原始DOM对象
                console.log(data.value); //被点击的radio的value值
                // $(this).parents('.layui-form-item').attr('value', data.value);
            });
    
            // 监听坐标系下拉
            form.on('select(coordinate)', function(data) {});
            // 监听坐标串
            $('.coordinateTextarea').on('blur', function() {
                // autoStartModel();
            })
    
            function formMonitor() {
                form.render();
            }
            formMonitor();
    
            window.inputChange = function(obj) {
                $(obj.parentElement).attr({
                    value: $(obj).val()
                })
                if (!$(obj).val()) {
                    return;
                }
                var obj1 = obj.parentElement.parentElement;
                $(obj1).addClass('paramItem')
                if (!$(obj1).next().length) {
                    $(obj1).clone(false).appendTo($(obj1).parent());
                    formMonitor();
                    $(obj1).next().find('input').val('');
                    $(obj1).next().removeClass('paramItem');
                    $(obj1).next().find('.layui-input-inline').attr({
                        value: ''
                    })
                }
            }
        });
    
        // 日期组件
        layui.use('laydate', function() {
            var laydate = layui.laydate;
            //执行一个laydate实例
            $('input.dateInput').each(function(index, item) {
                var id = $(this).attr('id')
                var defaultValue = $(this).attr('defaultValue') || new Date().getTime();
                console.log(id);
                laydate.render({
                    elem: '#' + id, //指定元素
                    value: new Date(defaultValue),
                });
            })
    
        })
    
        // // 点击选择或者绘制
        // 点击粘贴(选择专用)
        $('.drawBtn').on('click', function() {
            var $this = $(this);
            if ($this.hasClass('unable')) {
                return;
            }
            // var thisResult = '{"prj":"EPSG:3857","type":"polygon","points":[[12125526.314439269,4681162.043641863],[12125526.314439217,4676928.238350771],[12125526.314439217,4676928.238350771],[12127090.981612034,4678676.984014463]],"mode":"2D","features":{"displayFieldName":"","fieldAliases":{},"geometryType":"esriGeometryPolygon","spatialReference":{"wkid":"EPSG:3857","latestWkid":"EPSG:3857"},"fields":[],"features":[{"attributes":{},"geometry":{"rings":[[[12125526.314439269,4681162.043641863],[12125526.314439217,4676928.238350771],[12125526.314439217,4676928.238350771],[12127090.981612034,4678676.984014463]]]}}]}}'
            // $this.parent().parent().find('.json-textarea').val(JSON.stringify(thisResult))
    
            var thisResult = JSON.stringify($fmap[0].contentWindow.other_copyHeightLight());
            $this.parent().parent().find('.json-textarea').show();
            $this.parent().parent().find('.json-textarea').val(thisResult);
    
            // autoStartModel()
    
            // if ($this.html() == '选择') {
            //     var value = $('#layerSelect').val();
            //     if (value) {
            //         // alert(value);
            //         layer.min(layerIndex)
            //         $fmap[0].contentWindow.other_getFeature({
            //             type: "query", //"draw"绘制 or "query"查询
            //             layerGuid: value
            //         }, function (thisResult) {
            //             layer.restore(layerIndex)
            //             $('#json-textarea').val(JSON.stringify(thisResult))
            //         });
            //     } else {
            //         alert('请选择图层');
            //     }
            // } else {
            //     layer.min(layerIndex);
            //     $fmap[0].contentWindow.other_getFeature({
            //         type: "draw", //"draw"绘制 or "query"查询
            //     }, function (thisResult) {
            //         console.log(thisResult);
            //         layer.restore(layerIndex)
            //         $('#json-textarea').val(JSON.stringify(thisResult))
            //     });
            // }
    
    
            return;
            layer.min(layerIndex);
            [0].contentWindow.other_getFeature({
                type: "draw", //"draw"绘制 or "query"查询
            }, function(thisResult) {
                console.log(thisResult);
                layer.restore(layerIndex)
                // $('#json-textarea').val(JSON.stringify(thisResult))
                $this.parent().parent().find('.json-textarea').val(thisResult);
            });
    
    
        })
    
        // 点击上传文件
        $('.uploadBtn').on('click', function() {
            var $this = $(this);
            $this.parent().parent().find('.uploadFile').click();
        });
    
        $('.uploadFile').each(function(index, item) {
            var file = item;
            file.onchange = function() {
                var name = this.files[0].name;
                if (name.endsWith('.zip') || name.endsWith('.rar')) {
                    var $this = $(this);
                    var files = this.files[0]
    
                    new Promise(function(resolve, reject) {
                        var aliasName;
                        if (modelName.indexOf('(大数据)') > -1) {
                            layer.open({
                                type: 1,
                                title: '请提供一个文件别名',
                                content: `<div class="layui-form-item">
                                    <label class="layui-form-label">文件别名</label>
                                    <div class="layui-input-block">
                                        <input id="fileOtherName" type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入文件别名" class="layui-input layui-inputNew" value=""></div></div>`,
                                shade: 0.3,
                                close: false,
                                resize: false,
                                btn: ['确定'],
                                btn1: function(index, layero) {
                                    aliasName = $('#fileOtherName').val();
                                    if (aliasName.length) {
                                        layer.close(index);
                                        resolve(aliasName);
                                    } else {
                                        alert('请输入文件别名')
                                    }
                                },
                                cancel: function(index, layero) {
                                    aliasName = $('#fileOtherName').val();
                                    if (aliasName.length) {
                                        layer.close(index);
                                        resolve(aliasName);
                                    } else {
                                        alert('请输入文件别名')
                                        return false;
                                    }
                                }
                            });
                        } else {
                            resolve();
                        }
                    }).then(
                        function(res) {
                            var obj = {
                                userNo: userno,
                                userName: username,
                                file: files,
                            }
                            if (res) {
                                obj.aliasName = res;
                            }
                            var formData = new FormData();
                            $.each(obj, function(key, value) {
                                formData.append(key, value);
                            })
    
                            $this.parents('.layui-form-item')[0].formData = formData;
                            $this.parents('.layui-form-item').attr('fileName', '');
                            $this.parent().find('.uploaded').html('<div style="display:inline-block">上传中...</div>');
    
                            var url = fileUploadOrigin + '/sw/upload/uploadZip';
                            if (modelName.indexOf('(大数据)') > -1) {
                                // 判断是ga
                                url = fileUploadOrigin + '/sw/upload/gaZipUpload';
                            }
                            $.ajax({
                                type: 'post',
                                url: url,
                                cache: false,
                                contentType: false,
                                processData: false, //默认为true，默认情况下，发送的数据将被转换为对象，设为false不希望进行转换
                                data: formData, //数据
    
                                success: function(res, textStatus, jqXHR) {
                                    $this.parent().find('.uploaded').html('')
                                    if (typeof res == 'string') {
                                        res = JSON.parse(res);
                                    }
                                    if (res.code == 200) {
                                        $this.parents('.layui-form-item').attr('fileName', res.data);
                                        $this.parent().find('.uploaded').html('<div style="display:inline-block">' + $this[0].files[0].name + '</div>');
                                        // autoStartModel()
                                    } else {
                                        alert(res.msg);
                                        return false;
                                    }
                                },
                                error: function(err) {
                                    $this.parent().find('.uploaded').html('');
                                }
                            });
                        }
                    )
                } else {
                    alert('请打包成.zip或.rar后再上传');
                }
            }
        })
    }

function receiveCopyGeom(geom){
    $this.parent().parent().find('.json-textarea').show();
    $this.parent().parent().find('.json-textarea').val(geom);
}


/* 自动启动模型 */
function autoStartModel() {
    if ($('#modelForm>.layui-form-item').length == 1) {
        startModel();
    }
}
/* 启动模型 */
function startModel() {
    var analysisName = $('#fxName').val();
    var modelname = $('#modelForm').attr('modelname');
    var data = {};
    var canRun = true;
    var breakAll = false;

    $('#modelForm .layui-form-item').each(function() {
        if (breakAll) {
            return false;
        }
        var $this = $(this);
        var modelparamname = $this.attr('modelparamname');
        var name = $this.attr('name');
        var formtype = $this.attr('formtype');
        var formtypeNew = $this.attr('formtypeNew');
        var required = $this.attr('itemRequired');

        var value = '';
        var typeparamname = $this.attr('typeparamname');
        if (formtype == 'SDE') {
            if (!formtypeNew) {
                alert('请选择' + name)
                canRun = false;
                return false
            }
            // 选库选表
            if (!$this.attr('database')) {
                alert('请选择' + name + '的数据库和表名')
                canRun = false;
                return false
            }
            var database = $this.attr('database').split('/')[1];
            var table = $this.attr('table');
            if (database && table) {
                value = database + '/' + table;
                var key;
                if (modelparamname.indexOf('/') > -1) {
                    key = modelparamname.split('/')[1];
                } else {
                    key = modelparamname;
                }
                data[key] = value;

                // soe
                if (modelName.endWith('图制作')) {
                    data.Type = '2';
                } else if (typeparamname !== 'undefined') {
                    data[typeparamname] = false;
                }
            } else if (required == 'true') {
                alert('请选择' + name + '的数据库和表名')
                canRun = false;
                return false;
            }
        } else if (formtype == 'FILE') {
            if (!formtypeNew) {
                alert('请选择' + name)
                canRun = false;
                return false
            }
            var formData = $(this)[0].formData;
            value = $this.attr('fileName');
            if (formData) {
                // 上传文件接口
                var key;
                if (modelparamname.indexOf('/') > -1) {
                    key = modelparamname.split('/')[1];
                } else {
                    key = modelparamname;
                }
                data[key] = value;
                // soe
                if (modelName.endWith('图制作')) {
                    data.Type = '2';
                } else if (typeparamname !== 'undefined') {
                    data[typeparamname] = false;
                }
            } else if (required == 'true') {
                alert('请上传' + name + '的文件')
                canRun = false;
                return false;
            }
        } else if (formtype == 'JSON1' || formtype == 'JSON2') {
            if (!formtypeNew) {
                alert('请选择' + name)
                canRun = false;
                return false
            }
            // 上传json
            value = $this.find('textarea').val();
            if (value) {
                data[modelparamname.split('/')[0]] = value;
                // soe 
                if (modelName.endWith('图制作')) {
                    data.Type = '2';
                } else if (typeparamname !== 'undefined') {
                    data[typeparamname] = true;
                }
            } else if (required == 'true') {
                alert('请输入' + name + '的选择或绘制结果')
                canRun = false;
                return false;
            }
        } else if (formtype == 'coordinate') {
            if (!formtypeNew) {
                alert('请输入' + name)
                canRun = false;
                return false
            }

            var inSR = $('.coordinateSelect').val()
            var coords = $('.coordinateTextarea').val()

            if (inSR == '') {
                alert('请选择坐标系');
                canRun = false;
                return;
            } else if (coords == '') {
                alert('请输入坐标串');
                canRun = false;
                return;
            }

            var result = $fmap[0].contentWindow.other_coordsFormat({
                inSR: inSR,
                outSR: "EPSG:3857",
                coords: coords
            });
            if (result.code != 200) {
                alert(result.msg)
                canRun = false;
                return;
            }

            // 上传json
            value = JSON.stringify(result.data);
            if (value) {
                data[modelparamname.split('/')[0]] = value;
                // soe 
                if (modelName.endWith('图制作')) {
                    data.Type = '2';
                } else if (typeparamname !== 'undefined') {
                    data[typeparamname] = true;
                }
            } else if (required == 'true') {
                alert('请输入' + name + '的坐标串')
                canRun = false;
                return false;
            }

        } else if (formtype == 'XZQ') {
            if (!formtypeNew) {
                alert('请选择' + name)
                canRun = false;
                return false
            }
            // 选择行政区
            value = $this.find('.XZQinput').attr('nodeId');
            if (value) {
                var key;
                if (modelparamname.indexOf('/') > -1) {
                    key = modelparamname.split('/')[1];
                } else {
                    key = modelparamname;
                }
                // data[key] = value;
                // // soe 
                // if (modelName.endWith('图制作')) {
                //     data.Type = '0';
                // } else if (typeparamname !== 'undefined') {
                //     data[typeparamname] = false;
                // }
                var obj = JSON.stringify($fmap[0].contentWindow.globleGetXZQFeature(value));
                data = {
                    "jsonFeature":obj,
                    "IsJson":true
                }
            } else if (required == 'true') {
                alert('请选择' + name + '的行政区划')
                canRun = false;
                return false;
            }
        } else if (formtype == 'TFH') {
            if (!formtypeNew) {
                alert('请选择' + name)
                canRun = false;
                return false
            }
            // 输入图符号
            value = $this.find('.TFHinput').val();
            if (value) {
                var key;
                if (modelparamname.indexOf('/') > -1) {
                    key = modelparamname.split('/')[1];
                } else {
                    key = modelparamname;
                }
                data[key] = value;
                if (modelName.endWith('图制作')) {
                    data.Type = '1';
                } else if (typeparamname !== 'undefined') {
                    data[typeparamname] = false;
                }
            } else if (required == 'true') {
                alert('请输入' + name + '的图符号')
                canRun = false;
                return false;
            }
        } else if (formtype == 'input') {
            value = $this.find('input').val();
            if (value) {
                data[modelparamname] = value;
            } else if (required == 'true') {
                alert('请输入' + name);
                canRun = false;
                return false;
            }
        } else if (formtype == 'date') {
            value = $this.find('input').val();
            if (value) {
                data[modelparamname] = value;
            } else if (required == 'true') {
                alert('请输入' + name);
                canRun = false;
                return false;
            }
        } else if (formtype == 'option') {
            value = $this.find('select').val();
            // value = $this.attr('value')
            if (value) {
                data[modelparamname] = value;
            } else if (required == 'true') {
                alert('请输入' + name);
                canRun = false;
                return false;
            }
        } else if (formtype == 'radio') {
            value = $this.attr('value')
            if (value) {
                data[modelparamname] = value;
            } else if (required == 'true') {
                alert('请输入' + name);
                canRun = false;
                return false;
            }
        } else if (formtype == 'check') {
            value = $this.attr('value')
            if (value) {
                data[modelparamname] = value;
            } else if (required == 'true') {
                alert('请输入' + name);
                canRun = false;
                return false;
            }
        } else if (formtype == 'variableArray') {
            value = [];
            $this.find('.layui-input-block .paramItem').each(function(index, item) {
                if (breakAll) {
                    return false;
                }
                var object = {};
                $(item).find('.layui-input-inline').each(function(index1, item1) {
                    var key = $(item1).attr('modelparamname')
                    var inputValue = $(item1).attr('value');
                    if (!inputValue) {
                        alert('请输入' + name)
                        canRun = false;
                        breakAll = true;
                        return false;
                    } else {
                        object[key] = inputValue;
                    }
                })
                value.push(object)
            })
            if (canRun) {
                if (value.length) {
                    data[modelparamname] = value;
                } else if (required == 'true') {
                    alert('请输入' + name);
                    canRun = false;
                    return false;
                }
            }
        } else {
            alert('请输入' + name);
            canRun = false;
            return false;
        }
    });
    if (canRun) {
        layui.layer.close(layerIndex);
        var modelParam = [];
        checkedFactors = layui.form.val('checkFactorsForm');
        var oneModelId = getModelID();
        for(var i in checkedFactors){
            //随机生成Moedlid
            modelParam.push({
                // oneModelId:oneModelId,
                oneFactorName:checkedFactors[i]
            })
        }
        var startingMsg = layui.layer.msg('正在启动中,请稍后...', {
            shade: 0.3,
            // time: 1000 // 1秒关闭
        });
        var url = modelOrigin + '/sw/gpTask/start';
        if (modelName.indexOf('(大数据)') > -1) {
            url = modelOrigin + '/sw/gaTask/start';
        } else if (modelName.endWith('图制作')) {
            url = modelOrigin + '/sw/soeTask/start';
        }

        for(var i = 0;i<modelParam.length;i++){
            var paramData = {
                xzqname:xzqName,//用户自定义范围所占压的行政区
                name:analysisName != ""?analysisName:modelname,
                mxmc:modelname,//模型名称
                oneModelId:oneModelId,
                modelName: modelParam[i].oneFactorName,
                userno: userno,
                username: username,
                data: JSON.stringify(data)
            }
            $.ajax({
                type: 'post',
                async: true,
                url: url,
                data: paramData,
                datatype: 'json',
                success: function(res) {
                    layer.close(startingMsg);
                    if (typeof res == 'string') {
                        res = JSON.parse(res);
                    }
                    if (res.code == 200) {
                        // alert(res.msg);
                        var msg = layui.layer.msg(res.msg, {
                            shade: 0.3,
                            time: 1000 // 1秒关闭
                        });
                        window.parent.$('#fmain')[0].contentWindow.clickRundemoNew(modelName, resourceid, function(num) {
                            if (window.parent.$('#otherIframe').contents().find('.running').length) {
                                window.parent.$('#otherIframe').contents().find('.running').parent().prev().find('.runNum').html(num)
                            }
                        });
                        layer.close(layerIndex);
                    } else {
                        // alert(res.msg)
                        var msg = layui.layer.msg(res.msg, {
                            shade: 0.3,
                            time: 1000 // 1秒关闭
                        });
                    }
                },
                error: function(err) {
                    console.log(err);
                    var msg = layui.layer.msg('启动失败', {
                        shade: 0.3,
                        time: 1000 // 1秒关闭
                    });
                    layer.close(startingMsg);
                }
            });
        }
        xzqName = "";
        // $.ajax({
        //     type: 'post',
        //     async: true,
        //     url: url,
        //     data: {
        //         //新增有几个分析因子，start接口就执行几次,checkedFactors选中的分析因子的JSON字符串
        //         //新增name:"占压基本农田分析",oneModelId:"随机生成的id",modelName:"改成分析因子的名称"，
        //         modelName: modelname,
        //         userno: userno,
        //         username: username,
        //         data: JSON.stringify(data)
        //     },
        //     datatype: 'json',
        //     success: function(res) {
        //         layer.close(startingMsg);
        //         if (typeof res == 'string') {
        //             res = JSON.parse(res);
        //         }
        //         if (res.code == 200) {
        //             // alert(res.msg);
        //             var msg = layui.layer.msg(res.msg, {
        //                 shade: 0.3,
        //                 time: 1000 // 1秒关闭
        //             });
        //             window.parent.$('#fmain')[0].contentWindow.clickRundemoNew(modelName, resourceid, function(num) {
        //                 if (window.parent.$('#otherIframe').contents().find('.running').length) {
        //                     window.parent.$('#otherIframe').contents().find('.running').parent().prev().find('.runNum').html(num)
        //                 }
        //             });
        //             layer.close(layerIndex);
        //         } else {
        //             // alert(res.msg)
        //             var msg = layui.layer.msg(res.msg, {
        //                 shade: 0.3,
        //                 time: 1000 // 1秒关闭
        //             });
        //         }
        //     },
        //     error: function(err) {
        //         console.log(err);
        //         var msg = layui.layer.msg('启动失败', {
        //             shade: 0.3,
        //             time: 1000 // 1秒关闭
        //         });
        //         layer.close(startingMsg);
        //     }
        // });
    }
};

String.prototype.endsWith = function(suffix) {
    return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

var websocket = null;
var wsOrigin = $('#wsOrigin').val();
var randomId = userno + '_' + Math.random().toString(36).substr(-8)

if ('WebSocket' in window) {
    websocket = new WebSocket('ws://' + wsOrigin + '/sw/webSocket/' + randomId);
} else {
    console.log('当前浏览器不支持Websocket')
}

//连接发生错误的回调方法 
websocket.onerror = function() {
    // alert("WebSocket连接发生错误")
    console.log("WebSocket连接发生错误")
};

//连接成功建立的回调方法 
websocket.onopen = function() {
    // alert("WebSocket连接成功")
    console.log("WebSocket连接成功")
}

//接收到消息的回调方法 
websocket.onmessage = function(event) {
    // alert("接收到消息的回调方法")
    // alert("这是后台推送的消息：" + event.data);
    var data = event.data;
    data = JSON.parse(data)
    console.log(data);
    var title = data.data.modelName + '-运行已完成'
    if (data.code == 200) {
        // alert(data.message)
        document.getElementById("fmap").contentWindow.document.getElementById("mapTreeIframe").contentWindow.getAnalysisResultData();
        layer.open({
            type: 1,
            title: title,
            skin: 'myskin',
            shade: 0,
            // offset: 'rb',
            content: '<div id="detailDiv" style="margin: 20px;color: black;">' + data.message + '</div>',
            // area: ['300px', '200px'],
            btn: ['关闭'],
            btn1: function(index, layero) {
                layer.close(index);
            }
            // btn: ['结果查看', '挖掘'],
            // btn1: function(index, layero) {
            //     var jobId = data.data.jobId;
            //     var modelId = data.data.id;
            //     var modelName = data.data.modelName;
            //     var module = data.data.module;
            //     // var url = modelOrigin + '/sw/gpTask/jobJsonResult/' + jobId;
            //     // url更新为文件上传下载origin, uploadFile
            //     var url = fileUploadOrigin + '/sw/upload/jobJsonResult/' + jobId;
            //     var type = data.data.type;
            //     if (type == '1') {
            //         parent.window.document.getElementById('fmap').contentWindow.other_objectToGeometry({
            //             type: "url", // url json
            //             // object: "../../MapServer/Json/testPolygon.json"
            //             object: url,
            //             modelName: modelName
            //         });
            //     } else if (type == '2') {
            //         // ga
            //         var filename = $('.curSelectedNode').attr('filename');
            //         parent.window.document.getElementById('fmap').contentWindow.other_featureServerToGeometry({
            //             url: filename
            //         });
            //     } else if (type == '3') {
            //         var fileName = $('.curSelectedNode').attr('fileName');
            //         if (fileName != 'undefined') {
            //             var fileNameArr = fileName.split(',');
            //             fileNameArr.map(function(item, index) {
            //                 if (item) {
            //                     var url = fileUploadOrigin + '/sw/upload/soeDownload?name=' + item;
            //                     if (item.endWith('.PDF') || item.endWith('.pdf')) {
            //                         window.open('/scripts/pdfJs/web/viewer.html?file=' + encodeURIComponent(url), '_blank');
            //                     } else {
            //                         window.open('/BasePlatform/ModelDriven/showImg.html?file=' + encodeURIComponent(url), '_blank');
            //                     }
            //                 }
            //             });
            //         }
            //     }
            // },
            // btn2: function(index, layero) {
            //     var id = data.data.TB_DATAEXPLORE_ID;
            //     var dbname = data.data.dbname;
            //     var tablename = data.data.sdeName.split(',')[0];

            //     if (id && dbname && tablename) {
            //         var url = '/BasePlatform/SmartStatistics/BasicStaticsNew.html?isExcavate=true&id=' + id + '&dbname=' + dbname + '&tablename=' + tablename;
            //         $('#fexplore').attr('src', url);
            //     }
            //     $('#header_tab4').click();
            // },
        });
    } else {
        layer.open({
            type: 1,
            title: title,
            skin: 'myskin',
            shade: 0,
            offset: 'rb',
            content: '<div id="detailDiv" style="margin: 20px;">' + data.message + '</div>',
            area: ['300px', '200px'],
            btn: ['监控信息'],
            btn1: function(index, layero) {
                layer.alert(data.data.contentDetail, {
                    title: data.data.modelName + '-模型运行信息',
                    area: ['500px', '500px'],
                });
            },
        });
    }

    // var detail = confirm('要查看详细信息吗?')
    // if (detail) {
    //     alert(data.data.contentDetail)
    // }
    // if (data.code == 200) {
    //     var dig = confirm('要挖掘吗?')
    //     if (dig) {
    //         var id = data.data.TB_DATAEXPLORE_ID;
    //         var dbname = data.data.dbname;
    //         var tablename = data.data.sdeName.split(',')[0];

    //         if (id && dbname && tablename) {
    //             var url = '/BasePlatform/SmartStatistics/BasicStaticsNew.html?isExcavate=true&id=' + id + '&dbname=' + dbname + '&tablename=' + tablename;
    //             $('#fexplore').attr('src', url);
    //         }
    //         $('#header_tab4').click();
    //     }
    // }
}

//连接关闭的回调方法 
websocket.onclose = function() {
    console.log("WebSocket连接关闭");
}

//监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。 
window.onbeforeunload = function() {
    closeWebSocket();
}

//关闭WebSocket连接 
function closeWebSocket() {
    websocket.close();
}

//随机生成随机数
function getModelID(){
    var random = [];
    var hexDigits = "0123456789abcdefABCDEF";
    for (var i = 0; i < 32; i++) {
        random[i] = hexDigits.substr(Math.floor(Math.random() * 22), 1);
    }
    random[12] = "4"; 
    random[16] = hexDigits.substr(('0x' + random[16] & 0x3) | 0x8, 1);
    var randomData = random.join("");
    return randomData;
}

});
